package com.supermarket.view;

import com.supermarket.Main;
import com.supermarket.entity.CommodityEntity;
import com.supermarket.serivce.CommoditySerivce;
import com.supermarket.utils.ScannerUtil;

import java.util.ArrayList;

public class StockView {
    //创建CommodityService对象
    private static CommoditySerivce CommoditySerivce = new CommoditySerivce();
    //主窗口
    public void StockView() {
        while (true) {
            System.out.println("=======仓库管理=======");
            System.out.println("1. 出库功能");
            System.out.println("2. 展示出库记录");
            System.out.println("0. 返回上一级菜单");
            System.out.println("=======仓库管理=======");
            System.out.println("请输入菜单序号：");
            int result = ScannerUtil.getInt();
            switch (result) {
                case 1:
                    stockOut();
                    break;
                case 2:
                    showOutboundLog();
                    break;
                case 0:
                    Main.mainMenu();
                default:
                    System.out.println("您输入的菜单序号不正确，请重新输入!");
                    break;
            }
        }
    }
    //窗口 - 出库功能
    public void stockOut() {
        System.out.println("请输入商品ID：");
        Long commodityId = ScannerUtil.getLong();
        System.out.println("请输入出库数量：");
        Long quantity = ScannerUtil.getLong();

        int result = CommoditySerivce.stockOut(commodityId, quantity);
        if (result > 0) {
            System.out.println("出库成功");
        } else {
            System.out.println("出库失败");
        }
    }
    //窗口 - 展示出库记录
    public void showOutboundLog() {
        ArrayList<CommodityEntity> outboundLogs = CommoditySerivce.allOutbound();
        if (outboundLogs.isEmpty()) {
            System.out.println("当前没有出库记录。");
        } else {
            System.out.println("所有出库记录如下：");
            for (CommodityEntity log : outboundLogs) {
                System.out.println(log);
            }
        }
    }
}
